package com.suma.platform.core.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.nfsq.platform.utils.bean.ResultBean;
import com.suma.platform.core.config.SumaConfig;
import com.suma.platform.core.model.User;
import com.suma.platform.core.model.qo.WechatUserQO;
import com.suma.platform.core.service.WechatUserService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

/**
 * @author suma
 * @date 2017/11/27 下午1:25
 */
@RestController
@RequestMapping(value = "/api/user/wechat")
@Api(value = "/微信信息API")
public class WechatUserController {

	@Autowired
	WechatUserService wechatUserService;

	@Autowired
	SumaConfig sumaConfig;

	@ApiOperation(value = "获取微信用户信息", notes = "根据openid查询微信用户信息")
	@ApiImplicitParam(name = "openid", dataType = "String", value = "微信openid", required = true, paramType = "query")
	@RequestMapping(value = "/getWechatUserByOpenid", method = RequestMethod.POST)
	public ResultBean<User> getWechatUserByOpenid(@RequestParam("openid") String openid) {
		return new ResultBean<>(wechatUserService.getWechatUserByOpenid(openid));
	}

	@ApiOperation(value = "新增微信用户信息", notes = "新增微信用户信息")
	@ApiImplicitParam(name = "wechatUser", dataType = "WechatUser", value = "微信用户信息", required = true)
	@RequestMapping(value = "/insertWechatUser", method = RequestMethod.POST)
	public ResultBean<Integer> insertWechatUser(@RequestBody User wechatUser) {
		return new ResultBean<>(wechatUserService.insertWechatUser(wechatUser));
	}

	@ApiOperation(value = "微信用户信息列表", notes = "查询微信用户信息列表")
	@ApiImplicitParam(name = "wechatUserQO", dataType = "WechatUserQO", value = "微信用户查询", required = true)
	@RequestMapping(value = "/listWechatUsers", method = RequestMethod.POST)
	public ResultBean<PageInfo<User>> listWechatUsers(@RequestBody WechatUserQO wechatUserQO) {
		PageHelper.startPage(wechatUserQO.getPageNo(), wechatUserQO.getPageSize());
		List<User> list = wechatUserService.listWechatUsers(wechatUserQO);
		return new ResultBean<>(new PageInfo<User>(list));
	}

	@RequestMapping(value = "/getActualPrice", method = RequestMethod.POST)
	public ResultBean<Double> getActualPrice(Integer levelId) {
		double price = wechatUserService.getActualPrice(levelId);
		return new ResultBean<>(price);
	}
}
